<div class="layui-fluid">
    <div class="layui-card">
        <div id="body-div" class="layui-card-body">
        	<form id="searchForm" class="searchForm form-inline">
        		<div class="searchDiv positionSpc">
					<div class="form-group pull-left important">
						<span>日志和空间占比：</span>
						<span id="logSpace"></span>
						<span>登陆账号</span>
						<input name="s02" component-type="input" class="form-control" type="text" value="" maxlength="64" />
					</div>
					<div class="form-group pull-left ">
						<span>操作内容</span>
						<input name="s03" component-type="input" class="form-control" type="text" value="" maxlength="64" />
					</div>
					<div class="form-group pull-left ">
						<span>操作时间</span>
						<input name="beginD11" component-type="datePicker" readonly="readonly" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endD11\')}'})" id="beginD11" class="Wdate form-control" type="text" value="" />
					</div>
					<div class="form-group pull-left">
						<span>至</span>
						<input name="endD11" component-type="datePicker" readonly="readonly" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'beginD11\')}'})" id="endD11" class="Wdate form-control" type="text" value="" />
					</div>
					<div class="form-group pull-left ">
						<span>操作者IP</span>
						<input name="s05" component-type="input" class="form-control" type="text" value="" maxlength="64" />
					</div>
					<div class="form-group pull-left ">
						<span>操作类型</span>
						<input name="s06" component-type="input" class="form-control" type="text" value="" maxlength="64" />
					</div>
					<div class="form-group pull-left ">
						<span>操作结果</span>
						<input name="s07" component-type="input" class="form-control" type="text" value="" maxlength="64" />
					</div>
				</div>
        	</form>
        	<div id="toolbar" class="toolbar">
				<div class="pull-right">
					<a id="searchBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-search"></i> <font>查询</font></a>
					<a id="resetBtn" class="btn btn-success btn-bordered btn-sm"><i class="fa fa-refresh"></i> <font>重置</font></a>
					<a id="easySearch" class="btn btn-success btn-bordered btn-sm" style="display: none;"><i class="fa fa-backward"></i> <font>返回</font></a>
					<a id="hardSearch" class="btn btn-success btn-bordered btn-sm" style="display: inline-block;"><i class="fa fa-search-plus"></i> <font>高级查询</font></a>
				</div>
			</div>
            <form id="editTableForm">
				<table id="table-list"></table>
			</form>
        </div>
    </div>
</div>
<script>
    layui.use(['common', 'view', 'admin', 'laytpl'], function () {
        var $ = layui.$
            , R = layui.common
            , view = layui.view
            , admin = layui.admin
            , laytpl = layui.laytpl;

        var getTime = "-" + new Date().getTime();
        $("#body-div").attr("id", "body-div" + getTime);
        $("#table-list").attr("id","table-list" + getTime);
        var btnsStr = LayerUtil.getBtnsStrFromMenuData();

		var bootstrapTableUtil = new BootstrapTableUtil(getTime);
		bootstrapTableUtil.init({
			url: admin.basePath + '/system/secLog/data?path=path&traceFlag=&formNo=sys_sec_log',
			method: 'post',
			columns: [
                {
					checkbox: true
				},
				{
					field: 's02',
					title: '登陆账号',
					sortable: true,
					sortName: 'a.account_',
					
					formatter:function(value, row , index){
						if(!value){
							value = "";
						}
						return "<a href='javascript:;' class='view'>"+value+"</a>";
					},
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({
								id: row.id
							})
						}
					},
				},
				{
					field: 's03',
					title: '操作内容',
					sortable: true,
					sortName: 'a.content_',
					
				},
				{
					field: 'd11',
					title: '操作时间',
					sortable: true,
					sortName: 'a.time_',
					
					formatter:function(value, row, index){
						return (typeof value == "undefined" || value == null || value == "") ? "" : moment(value).format('yyyy-MM-dd HH:mm:ss'.replace(/yy/g,"YY").replace(/dd/g,"DD"));
					},
				},
				{
					field: 's05',
					title: '操作者IP',
					sortable: true,
					sortName: 'a.ip_',
					
				},
				{
					field: 's06',
					title: '操作类型',
					sortable: true,
					sortName: 'a.type_',
					
				},
				{
					field: 's07',
					title: '操作结果',
					sortable: true,
					sortName: 'a.result_',
					
				},
                {
                	title: layui.admin.lang() ? 'Operation' : '操作',
                	width: '45px',
					"class": 'center must',
					events: {
						'click .view': function (e, value, row, index) {
							viewForm({id: row.id})
						},
						'click .edit': function (e, value, row, index) {
							addOrEdit({
								id: row.id
							})
						},
						'click .del': function (e, value, row, index) {
							delFuc(row);
						},
					},
					formatter: function(value, row, index) {
						return btnsStr.tableBtnsStr;
					},
                },
            ],
		},"sys_sec_log");


		$("#body-div"+getTime).find("#addBtn").on("click",function(){
			addOrEdit({});
		});

		$("#body-div"+getTime).find("#removeBtn").on("click",function(){
			var ids = bootstrapTableUtil.getMultiId();
			if(ids){
				LayerUtil.confirm(layui.admin.lang() ? "Are you sure?" : "确定删除吗？", function(){
					LayerUtil.ajax({
						type: 'post',
		        		url: admin.basePath + '/dynamic/zform/delete?formNo=sys_sec_log&ids=' + ids,
		        		success: function(res){
		        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
                			bootstrapTableUtil.refresh();
		        		}
		        	})
				})
	       	}
		});

		function addOrEdit(initData) {
			var id = initData ? initData.id : '';
			LayerUtil.openDialog({
				title : layui.admin.lang() ? 'New ' : '添加系统日志',
				formLay : 'sys_sec_log',
				initData : initData,
				setDataWidthAjax : true,
				actionDataName : 'data',
				url : 'admin/sys_sec_log/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=sys_sec_log&id=' + id,
	            btn : ['保存', '取消'],
	            btn_EN : ['Save', 'Cancel'],
	            func1 : function(index,layero) {
	            	var validateForm = $(layero).find("#inputForm").validate({});
	            	if(validateForm.form()){
						var data = myHelper.composeData($(layero).find("#inputForm"));
						LayerUtil.ajax({
							url : admin.basePath + '/dynamic/zform/save',
							type : 'post',
							data : JSON.stringify(data),
							shade: true,
							success : function(res) {
								LayerUtil.success(res[LayerUtil.getMsgLang()]);
								bootstrapTableUtil.refresh();
								layui.layer.close(index);
							}
						});
	            	}
	            }
			})
		}

		function addChild(initData) {
			var id = initData ? initData.id : '';
			LayerUtil.openDialog({
				title : layui.admin.lang() ? 'New ' : '添加系统日志',
				formLay : 'sys_sec_log',
				initData : initData,
				setDataWithoutAjax : true,
				actionDataName : 'data',
				url : 'admin/sys_sec_log/form',
	            btn : ['保存', '取消'],
	            btn_EN : ['Save', 'Cancel'],
	            func1 : function(index,layero) {
	            	var validateForm = $(layero).find("#inputForm").validate({});
	            	if(validateForm.form()){
						var data = myHelper.composeData($(layero).find("#inputForm"));
						LayerUtil.ajax({
							url : admin.basePath + '/dynamic/zform/save',
							type : 'post',
							data : JSON.stringify(data),
							shade: true,
							success : function(res) {
								LayerUtil.success(res[LayerUtil.getMsgLang()]);
								bootstrapTableUtil.refresh();
								layui.layer.close(index);
							}
						});
					}
	            }
			})
		}

		function viewForm(initData) {
			LayerUtil.openDialogView({
				title : layui.admin.lang() ? 'View ' : '查看系统日志',
				initData : initData,
				formLay : 'sys_sec_log',
				url : 'admin/sys_sec_log/form',
				actionUrl : admin.basePath + '/dynamic/zform/getZform?formNo=sys_sec_log&id=' + initData.id,
				actionDataName : 'data',
				setDataWidthAjax : true,
			})
		}

		function delFuc(row){
    		LayerUtil.confirm(layui.admin.lang() ? 'Are you sure you want to delete?':'确认要删除吗？', function() {
				LayerUtil.ajax({
					url: admin.basePath + '/dynamic/zform/delete?formNo=sys_sec_log&ids=' + row.id,
					type:'post',
	        		shade:true,
					success: function(res){
	        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
                			bootstrapTableUtil.refresh();
	        		}
				});
			});
    	}
		
		function showSecLogSpace() {
			LayerUtil.ajax({
				url: admin.basePath + '/system/secLog/getSecLogSpace',
				type:'get',
	        	shade:true,
				success: function(res){
	        		var logSpace = $("#logSpace");
	        		logSpace.css("color", res.data.color);
	        		logSpace.html(res.data.result);
	        	}
			});
		}
		showSecLogSpace();
    });
</script>
